package com.banter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ChatActivity extends Activity implements OnClickListener {
	private Button m_Send;
	private TextView m_Title;
	private TextView m_Body;
	private TextView m_Location;
	private EditText m_Userinput;
	private String Userinput;
	private LinearLayout m_Chat;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_chat);
		initLayout();
		m_Send.setOnClickListener(this);
	}
	
	protected void initLayout(){
    	m_Send = (Button) this.findViewById(R.id.button1);
    	m_Title = (TextView) this.findViewById(R.id.textView1);
    	m_Body = (TextView) this.findViewById(R.id.textView2);
    	m_Userinput = (EditText) this.findViewById(R.id.editText1);
    	m_Chat = (LinearLayout) this.findViewById(R.id.Chat);
    	m_Location = (TextView) this.findViewById(R.id.textView3);
    	getTitleAndBody();
    }
	
	public void getTitleAndBody(){
		Intent intent = getIntent();
    	String title = (String) intent.getExtras().get("title");
    	m_Title.setText(title);
    	String body = (String) intent.getExtras().get("body");
    	m_Body.setText(body);
    	
    	double lat = intent.getDoubleExtra("lattitude", 0.0);
    	double lng = intent.getDoubleExtra("longitude", 0.0);
    	
    	m_Location.setText("Location: ( "+lat+", "+lng+" )");
	}
	
	@Override
	public void onClick(View v) {
		 Userinput = "-" + m_Userinput.getText().toString();
		 TextView newItemTextView = new TextView(this);
		 newItemTextView.setText(Userinput);
		 m_Chat.addView(newItemTextView);
		 m_Userinput.setText("");
		 
	}
	
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_chat, menu);
		return true;
	}

}
